﻿/**  PACS v1.0
* BP_PatientBasicInfo.cs
*
* 类 名： BP_PatientBasicInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:26   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:BP_PatientBasicInfo
	/// </summary>
	public partial class BP_PatientBasicInfo
	{
		public BP_PatientBasicInfo()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BP_PatientBasicInfo");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.BP_PatientBasicInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.DangAnNo != null)
			{
				strSql1.Append("DangAnNo,");
				strSql2.Append("'"+model.DangAnNo+"',");
			}
			if (model.ShenFenZhengNo != null)
			{
				strSql1.Append("ShenFenZhengNo,");
				strSql2.Append("'"+model.ShenFenZhengNo+"',");
			}
			if (model.XingMing != null)
			{
				strSql1.Append("XingMing,");
				strSql2.Append("'"+model.XingMing+"',");
			}
			if (model.ZhiYe != null)
			{
				strSql1.Append("ZhiYe,");
				strSql2.Append("'"+model.ZhiYe+"',");
			}
			if (model.XingBie != null)
			{
				strSql1.Append("XingBie,");
				strSql2.Append("'"+model.XingBie+"',");
			}
			if (model.MinZu != null)
			{
				strSql1.Append("MinZu,");
				strSql2.Append("'"+model.MinZu+"',");
			}
			if (model.HuJi != null)
			{
				strSql1.Append("HuJi,");
				strSql2.Append("'"+model.HuJi+"',");
			}
			if (model.ChuShengRiQi != null)
			{
				strSql1.Append("ChuShengRiQi,");
				strSql2.Append("'"+model.ChuShengRiQi+"',");
			}
			if (model.XianZhuZhi != null)
			{
				strSql1.Append("XianZhuZhi,");
				strSql2.Append("'"+model.XianZhuZhi+"',");
			}
			if (model.GongZuoDanWei != null)
			{
				strSql1.Append("GongZuoDanWei,");
				strSql2.Append("'"+model.GongZuoDanWei+"',");
			}
			if (model.DianHua != null)
			{
				strSql1.Append("DianHua,");
				strSql2.Append("'"+model.DianHua+"',");
			}
			if (model.LianXiRen != null)
			{
				strSql1.Append("LianXiRen,");
				strSql2.Append("'"+model.LianXiRen+"',");
			}
			if (model.LianXiRenDianHua != null)
			{
				strSql1.Append("LianXiRenDianHua,");
				strSql2.Append("'"+model.LianXiRenDianHua+"',");
			}
			if (model.HunShi != null)
			{
				strSql1.Append("HunShi,");
				strSql2.Append("'"+model.HunShi+"',");
			}
			if (model.XueXing != null)
			{
				strSql1.Append("XueXing,");
				strSql2.Append("'"+model.XueXing+"',");
			}
			if (model.RHXueXing != null)
			{
				strSql1.Append("RHXueXing,");
				strSql2.Append("'"+model.RHXueXing+"',");
			}
			if (model.HuJiDiShengID != null)
			{
				strSql1.Append("HuJiDiShengID,");
				strSql2.Append("'"+model.HuJiDiShengID+"',");
			}
			if (model.HuJiDiShiID != null)
			{
				strSql1.Append("HuJiDiShiID,");
				strSql2.Append("'"+model.HuJiDiShiID+"',");
			}
			if (model.HuJiDiXingZhengQuID != null)
			{
				strSql1.Append("HuJiDiXingZhengQuID,");
				strSql2.Append("'"+model.HuJiDiXingZhengQuID+"',");
			}
			if (model.HuJiDiSheng != null)
			{
				strSql1.Append("HuJiDiSheng,");
				strSql2.Append("'"+model.HuJiDiSheng+"',");
			}
			if (model.HuJiDiShi != null)
			{
				strSql1.Append("HuJiDiShi,");
				strSql2.Append("'"+model.HuJiDiShi+"',");
			}
			if (model.HuJiDiXingZhengQu != null)
			{
				strSql1.Append("HuJiDiXingZhengQu,");
				strSql2.Append("'"+model.HuJiDiXingZhengQu+"',");
			}
			if (model.HuJiDiZhi != null)
			{
				strSql1.Append("HuJiDiZhi,");
				strSql2.Append("'"+model.HuJiDiZhi+"',");
			}
			if (model.QuYvBianMa != null)
			{
				strSql1.Append("QuYvBianMa,");
				strSql2.Append("'"+model.QuYvBianMa+"',");
			}
			if (model.QuYvMingCheng != null)
			{
				strSql1.Append("QuYvMingCheng,");
				strSql2.Append("'"+model.QuYvMingCheng+"',");
			}
			strSql.Append("insert into BP_PatientBasicInfo(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.BP_PatientBasicInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BP_PatientBasicInfo set ");
			if (model.DangAnNo != null)
			{
				strSql.Append("DangAnNo='"+model.DangAnNo+"',");
			}
			else
			{
				strSql.Append("DangAnNo= null ,");
			}
			if (model.ShenFenZhengNo != null)
			{
				strSql.Append("ShenFenZhengNo='"+model.ShenFenZhengNo+"',");
			}
			else
			{
				strSql.Append("ShenFenZhengNo= null ,");
			}
			if (model.XingMing != null)
			{
				strSql.Append("XingMing='"+model.XingMing+"',");
			}
			else
			{
				strSql.Append("XingMing= null ,");
			}
			if (model.ZhiYe != null)
			{
				strSql.Append("ZhiYe='"+model.ZhiYe+"',");
			}
			else
			{
				strSql.Append("ZhiYe= null ,");
			}
			if (model.XingBie != null)
			{
				strSql.Append("XingBie='"+model.XingBie+"',");
			}
			else
			{
				strSql.Append("XingBie= null ,");
			}
			if (model.MinZu != null)
			{
				strSql.Append("MinZu='"+model.MinZu+"',");
			}
			else
			{
				strSql.Append("MinZu= null ,");
			}
			if (model.HuJi != null)
			{
				strSql.Append("HuJi='"+model.HuJi+"',");
			}
			else
			{
				strSql.Append("HuJi= null ,");
			}
			if (model.ChuShengRiQi != null)
			{
				strSql.Append("ChuShengRiQi='"+model.ChuShengRiQi+"',");
			}
			else
			{
				strSql.Append("ChuShengRiQi= null ,");
			}
			if (model.XianZhuZhi != null)
			{
				strSql.Append("XianZhuZhi='"+model.XianZhuZhi+"',");
			}
			else
			{
				strSql.Append("XianZhuZhi= null ,");
			}
			if (model.GongZuoDanWei != null)
			{
				strSql.Append("GongZuoDanWei='"+model.GongZuoDanWei+"',");
			}
			else
			{
				strSql.Append("GongZuoDanWei= null ,");
			}
			if (model.DianHua != null)
			{
				strSql.Append("DianHua='"+model.DianHua+"',");
			}
			else
			{
				strSql.Append("DianHua= null ,");
			}
			if (model.LianXiRen != null)
			{
				strSql.Append("LianXiRen='"+model.LianXiRen+"',");
			}
			else
			{
				strSql.Append("LianXiRen= null ,");
			}
			if (model.LianXiRenDianHua != null)
			{
				strSql.Append("LianXiRenDianHua='"+model.LianXiRenDianHua+"',");
			}
			else
			{
				strSql.Append("LianXiRenDianHua= null ,");
			}
			if (model.HunShi != null)
			{
				strSql.Append("HunShi='"+model.HunShi+"',");
			}
			else
			{
				strSql.Append("HunShi= null ,");
			}
			if (model.XueXing != null)
			{
				strSql.Append("XueXing='"+model.XueXing+"',");
			}
			else
			{
				strSql.Append("XueXing= null ,");
			}
			if (model.RHXueXing != null)
			{
				strSql.Append("RHXueXing='"+model.RHXueXing+"',");
			}
			else
			{
				strSql.Append("RHXueXing= null ,");
			}
			if (model.HuJiDiShengID != null)
			{
				strSql.Append("HuJiDiShengID='"+model.HuJiDiShengID+"',");
			}
			else
			{
				strSql.Append("HuJiDiShengID= null ,");
			}
			if (model.HuJiDiShiID != null)
			{
				strSql.Append("HuJiDiShiID='"+model.HuJiDiShiID+"',");
			}
			else
			{
				strSql.Append("HuJiDiShiID= null ,");
			}
			if (model.HuJiDiXingZhengQuID != null)
			{
				strSql.Append("HuJiDiXingZhengQuID='"+model.HuJiDiXingZhengQuID+"',");
			}
			else
			{
				strSql.Append("HuJiDiXingZhengQuID= null ,");
			}
			if (model.HuJiDiSheng != null)
			{
				strSql.Append("HuJiDiSheng='"+model.HuJiDiSheng+"',");
			}
			else
			{
				strSql.Append("HuJiDiSheng= null ,");
			}
			if (model.HuJiDiShi != null)
			{
				strSql.Append("HuJiDiShi='"+model.HuJiDiShi+"',");
			}
			else
			{
				strSql.Append("HuJiDiShi= null ,");
			}
			if (model.HuJiDiXingZhengQu != null)
			{
				strSql.Append("HuJiDiXingZhengQu='"+model.HuJiDiXingZhengQu+"',");
			}
			else
			{
				strSql.Append("HuJiDiXingZhengQu= null ,");
			}
			if (model.HuJiDiZhi != null)
			{
				strSql.Append("HuJiDiZhi='"+model.HuJiDiZhi+"',");
			}
			else
			{
				strSql.Append("HuJiDiZhi= null ,");
			}
			if (model.QuYvBianMa != null)
			{
				strSql.Append("QuYvBianMa='"+model.QuYvBianMa+"',");
			}
			else
			{
				strSql.Append("QuYvBianMa= null ,");
			}
			if (model.QuYvMingCheng != null)
			{
				strSql.Append("QuYvMingCheng='"+model.QuYvMingCheng+"',");
			}
			else
			{
				strSql.Append("QuYvMingCheng= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BP_PatientBasicInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BP_PatientBasicInfo ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.BP_PatientBasicInfo GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,DangAnNo,ShenFenZhengNo,XingMing,ZhiYe,XingBie,MinZu,HuJi,ChuShengRiQi,XianZhuZhi,GongZuoDanWei,DianHua,LianXiRen,LianXiRenDianHua,HunShi,XueXing,RHXueXing,HuJiDiShengID,HuJiDiShiID,HuJiDiXingZhengQuID,HuJiDiSheng,HuJiDiShi,HuJiDiXingZhengQu,HuJiDiZhi,QuYvBianMa,QuYvMingCheng ");
			strSql.Append(" from BP_PatientBasicInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.BP_PatientBasicInfo model=new Pacs.Model.BP_PatientBasicInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.BP_PatientBasicInfo DataRowToModel(DataRow row)
		{
			Pacs.Model.BP_PatientBasicInfo model=new Pacs.Model.BP_PatientBasicInfo();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["DangAnNo"]!=null)
				{
					model.DangAnNo=row["DangAnNo"].ToString();
				}
				if(row["ShenFenZhengNo"]!=null)
				{
					model.ShenFenZhengNo=row["ShenFenZhengNo"].ToString();
				}
				if(row["XingMing"]!=null)
				{
					model.XingMing=row["XingMing"].ToString();
				}
				if(row["ZhiYe"]!=null)
				{
					model.ZhiYe=row["ZhiYe"].ToString();
				}
				if(row["XingBie"]!=null)
				{
					model.XingBie=row["XingBie"].ToString();
				}
				if(row["MinZu"]!=null)
				{
					model.MinZu=row["MinZu"].ToString();
				}
				if(row["HuJi"]!=null)
				{
					model.HuJi=row["HuJi"].ToString();
				}
				if(row["ChuShengRiQi"]!=null && row["ChuShengRiQi"].ToString()!="")
				{
					model.ChuShengRiQi=DateTime.Parse(row["ChuShengRiQi"].ToString());
				}
				if(row["XianZhuZhi"]!=null)
				{
					model.XianZhuZhi=row["XianZhuZhi"].ToString();
				}
				if(row["GongZuoDanWei"]!=null)
				{
					model.GongZuoDanWei=row["GongZuoDanWei"].ToString();
				}
				if(row["DianHua"]!=null)
				{
					model.DianHua=row["DianHua"].ToString();
				}
				if(row["LianXiRen"]!=null)
				{
					model.LianXiRen=row["LianXiRen"].ToString();
				}
				if(row["LianXiRenDianHua"]!=null)
				{
					model.LianXiRenDianHua=row["LianXiRenDianHua"].ToString();
				}
				if(row["HunShi"]!=null)
				{
					model.HunShi=row["HunShi"].ToString();
				}
				if(row["XueXing"]!=null)
				{
					model.XueXing=row["XueXing"].ToString();
				}
				if(row["RHXueXing"]!=null)
				{
					model.RHXueXing=row["RHXueXing"].ToString();
				}
				if(row["HuJiDiShengID"]!=null)
				{
					model.HuJiDiShengID=row["HuJiDiShengID"].ToString();
				}
				if(row["HuJiDiShiID"]!=null)
				{
					model.HuJiDiShiID=row["HuJiDiShiID"].ToString();
				}
				if(row["HuJiDiXingZhengQuID"]!=null)
				{
					model.HuJiDiXingZhengQuID=row["HuJiDiXingZhengQuID"].ToString();
				}
				if(row["HuJiDiSheng"]!=null)
				{
					model.HuJiDiSheng=row["HuJiDiSheng"].ToString();
				}
				if(row["HuJiDiShi"]!=null)
				{
					model.HuJiDiShi=row["HuJiDiShi"].ToString();
				}
				if(row["HuJiDiXingZhengQu"]!=null)
				{
					model.HuJiDiXingZhengQu=row["HuJiDiXingZhengQu"].ToString();
				}
				if(row["HuJiDiZhi"]!=null)
				{
					model.HuJiDiZhi=row["HuJiDiZhi"].ToString();
				}
				if(row["QuYvBianMa"]!=null)
				{
					model.QuYvBianMa=row["QuYvBianMa"].ToString();
				}
				if(row["QuYvMingCheng"]!=null)
				{
					model.QuYvMingCheng=row["QuYvMingCheng"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,DangAnNo,ShenFenZhengNo,XingMing,ZhiYe,XingBie,MinZu,HuJi,ChuShengRiQi,XianZhuZhi,GongZuoDanWei,DianHua,LianXiRen,LianXiRenDianHua,HunShi,XueXing,RHXueXing,HuJiDiShengID,HuJiDiShiID,HuJiDiXingZhengQuID,HuJiDiSheng,HuJiDiShi,HuJiDiXingZhengQu,HuJiDiZhi,QuYvBianMa,QuYvMingCheng ");
			strSql.Append(" FROM BP_PatientBasicInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,DangAnNo,ShenFenZhengNo,XingMing,ZhiYe,XingBie,MinZu,HuJi,ChuShengRiQi,XianZhuZhi,GongZuoDanWei,DianHua,LianXiRen,LianXiRenDianHua,HunShi,XueXing,RHXueXing,HuJiDiShengID,HuJiDiShiID,HuJiDiXingZhengQuID,HuJiDiSheng,HuJiDiShi,HuJiDiXingZhengQu,HuJiDiZhi,QuYvBianMa,QuYvMingCheng ");
			strSql.Append(" FROM BP_PatientBasicInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BP_PatientBasicInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from BP_PatientBasicInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

